package cn.iocoder.yudao.module.lowcode.enums;

import cn.iocoder.yudao.framework.common.core.ArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 字段命名规则枚举
 *
 * @author 芋道源码
 */
@AllArgsConstructor
@Getter
public enum NamingConventionEnum implements ArrayValuable<String> {

    SNAKE_CASE("snake_case", "下划线命名", "user_id, created_at, is_active"),
    UPPER_SNAKE_CASE("upper_snake_case", "大写下划线命名", "USER_ID, CREATED_AT, IS_ACTIVE"),
    CAMEL_CASE("camelCase", "驼峰命名", "userId, createdAt, isActive"),
    PASCAL_CASE("PascalCase", "帕斯卡命名", "UserId, CreatedAt, IsActive"),
    KEBAB_CASE("kebab-case", "短横线命名", "user-id, created-at, is-active"),
    LOWER_CASE("lowercase", "全小写", "userid, createdat, isactive"),
    UPPER_CASE("UPPERCASE", "全大写", "USERID, CREATEDAT, ISACTIVE"),
    AUTO_DETECT("auto_detect", "自动检测", "系统自动分析字段命名模式"),
    CUSTOM("custom", "自定义规则", "使用自定义的转换规则");

    /**
     * 规则代码
     */
    private final String code;
    
    /**
     * 规则名称
     */
    private final String name;
    
    /**
     * 示例
     */
    private final String example;

    @Override
    public String[] array() {
        return Arrays.stream(values()).map(NamingConventionEnum::getCode).toArray(String[]::new);
    }

    public static NamingConventionEnum fromCode(String code) {
        return Arrays.stream(values())
                .filter(convention -> convention.getCode().equals(code))
                .findFirst()
                .orElse(SNAKE_CASE); // 默认使用下划线命名
    }
}